import threading
from time import sleep, ctime

"""
进行threading模块的使用,进行直接的调用
"""

# 每个线程的时间
loop_time_list = [4, 2]
# 每个线程执行的函数
def loop(loop_mem, loop_time):
    print('start loop {} at {}'.format(loop_mem, ctime()))
    sleep(loop_time)
    print('loop {} done at {}'.format(loop_mem, ctime()))


def main():
    print('Programming start at: {}'.format(ctime()))
    threads = []
    # 线程数
    loop_num = range(len(loop_time_list))

    # create threads
    for i in loop_num:
        t = threading.Thread(target=loop, args=(i, loop_time_list[i], ))
        threads.append(t)
    
    # start threads
    for i in loop_num:
        threads[i].start()
    
    print('all done at {}'.format(ctime()))


if __name__ == "__main__":
    main()